{include file="public/header"}
<body>
<fieldset class="layui-elem-field">
    <legend>激活码汇总</legend>
    <div class="layui-field-box">
        <form id="seachForm" method="" action="">
            <div class="layui-inline">
                <label class="layui-form-label">代理商姓名</label>
                <div class="layui-input-inline">
                    <input type="text" name="agent_name" value="" placeholder="如：和诚" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">按激活码</label>
                <div class="layui-input-inline">
                    <input type="text" name="phone" value="" placeholder="例如：3dg6g" autocomplete="off" class="layui-input">
                </div>
            </div>
            <span id="seach" class="layui-btn layui-btn-normal"><i class="layui-icon">&#xe615;</i> 按条件收索</span>
        </form>

        <table class="layui-table" lay-even>
            <thead>
            <tr>
                <th>#</th>
                <th>代理商名字</th>
                <th>代理商电话</th>
                <th>拥有激活码</th>
                <th>已激活</th>
                <th>操作</th>
            </tr>
            </thead>
            <tbody  id="searchContent">
                {volist name="list" id="vo"}
                    <tr>
                        <td>{$i}</td>
                        <td>{$vo['name']}</td>
                        <td>{$vo['mobile']}</td>
                        <td>{$vo['total']}</td>
                        <td>{$vo['enabled']}</td>
                        <td width="25%">
                            <span data-url="{:url('keyDetail', array('id' => $vo['id']))}" class="layui-btn detail">查看详情</span>
                            <span data-url="{:url('allotCode', array('id' => $vo['id']))}" class="layui-btn detail layui-btn-normal">分配激活码</span>
                        </td>
                    </tr>
                {/volist}
            </tbody>
        </table>
    </div>
</fieldset>


{include file="public/footer"}
<script>
    function searchEdit(id) {
        layer.open({
            type: 2,
            area: ['90%', '90%'],
            maxmin: true,
            content: '/admin/agent/edit/id/'+id
        });
    }
    function deleteSearch(id) {
        layer.confirm('你确定要删除该代理商么?', {
            btn: ['确定','取消'] //按钮
        }, function(){
            $.ajax({
                type: "POST",
                url: 'agent/del',
                data: {id:id},
                success: function(msg){
                    if( msg.errorCode == 0 ){
                        layer.msg(msg.msg,{time:1800},function(){
                            location.reload();
                        });
                    }else{
                        layer.msg(msg.msg, {
                            icon: 5,
                            shade: [0.6, '#393D49'],
                            time:1500
                        });
                    }
                }
            });
        });
    }
    $('#seach').on('click', function () {
        var params  = {
            url : "{:url('admin/agent/index')}",
            data: $("#seachForm").serialize(),
            type: 'post',
            sCallback:function(res){
                var travelHtml = [];
                for (var i=0; i < res.data.length; i++) {
                    var id = res.data[i]["id"];
                    travelHtml +='<tr> ' + '<td>'+(i+1)+'</td> ' +
                            '<td>'+res.data[i]["name"]+'</td> ' +
                            '<td>'+res.data[i]["mobile"]+'</td> ' +
                            '<td>'+res.data[i]["agent_num"]+'</td> ' +
                            '<td>'+res.data[i]["uper_name"]+'</td> ' +
                            '<td>'+res.data[i]["account"]+'</td> ' +
                            '<td>' +
                            '{if condition="'+ res.data[i][status] + ' === 0"} ' +
                            '<span style="border-radius: 2px;background-color: #FF5722;padding:5px 10px;color: #ffffff">禁用</span>' +
                            '{else /} ' +
                            '<span style="border-radius: 2px;background-color: #5FB878;padding:5px 10px;color: #ffffff">正常</span>' +
                            '{/if} ' +
                            '</td> ' +
                            '<td> ' +
                            '<span onclick="searchEdit('+ id +')"  class="layui-btn edit1 layui-btn-normal">编辑</span>' +
                            '<span onclick="deleteSearch('+ id +')" class="layui-btn layui-btn-danger confirm">删除</span> ' +
                            '</td> ' + '</tr>';
                };
                $('#searchContent').html(travelHtml);
            }
        };
        common.request(params);
    });



    layui.use(['layer'], function() {
        $('#searchContent .detail').on('click', function () {
            var ownObj = $(this);
            layer.open({
                type: 2,
                area: ['90%', '90%'],
                maxmin: true,
                content: ownObj.attr('data-url')
            });
        });
        $('#searchContent .confirm').on('click', function () {
            var ownObj = $(this);
            layer.confirm(ownObj.attr('data-info'), {
                btn: ['确定','取消'] //按钮
            }, function(){
                $.ajax({
                    type: "POST",
                    url: ownObj.attr('data-url'),
                    data: {id:ownObj.attr('data-id')},
                    success: function(msg){
                        if( msg.errorCode == 0 ){
                            layer.msg(msg.msg,{time:1800},function(){
                                location.reload();
                            });
                        }else{
                            layer.msg(msg.msg, {
                                icon: 5,
                                shade: [0.6, '#393D49'],
                                time:1500
                            });
                        }
                    }
                });
            });
        });
    });
</script>
</body>
</html>